Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Missing Ingestion Jobs from WebUI Table #679

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AVMatthews
Copy link
Contributor

@AVMatthews AVMatthews commented Jan 20, 2025

Description

#667

When ingestion jobs are submitted at a fast enough pace the ingestion table in the UI would be missing some of the submitted jobs. The ingestion table would request the most recent 5 jobs when looking for jobs and if job came quicker in the previous time period, not all jobs would be reflected in the UI.

FIX:

  • Remove job limit
  • Add time stamps for when updates occur to the compression jobs table
  • Maintain global last update request timestamp
  • Request updates for all jobs which were updated after the last update request timestamp

Validation performed

Submitted increasingly large number soft background compression jobs and made sure that they were all reflected in the table and that the updated to the status in the ingestion table occur accordingly.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new update_time column to track the last update timestamp for compression jobs.
    • Enhanced job retrieval mechanism to use timestamp-based filtering.
  • Improvements

    • Simplified compression job retrieval process.
    • Improved tracking of job metadata updates.

These changes enhance the system's efficiency in tracking and retrieving compression job information.

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request introduces a new update_time column to the compression jobs table across multiple components. This change enables more precise tracking of job metadata updates by adding a timestamp that records when a job's information was last modified. The modification spans database initialization, job scheduling, and web UI components, ensuring consistent timestamp tracking for compression jobs.

Changes

File Change Summary
components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py Added update_time column to COMPRESSION_JOBS_TABLE_NAME as DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(), and created index LAST_UPDATE_TIME on update_time.
components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py Updated update_compression_job_metadata to include update_time = CURRENT_TIMESTAMP() in SQL update statements.
components/webui/imports/api/ingestion/constants.js Added UPDATE_TIME: "update_time" to COMPRESSION_JOBS_TABLE_COLUMN_NAMES enumeration.
components/webui/imports/api/ingestion/server/CompressionDbManager.js Refactored getCompressionJobs method to use lastUpdateTimestampSeconds for filtering jobs.
components/webui/imports/api/ingestion/server/publications.js Removed COMPRESSION_MAX_RETRIEVE_JOBS constant, added lastUpdateTimestampSeconds variable initialized to zero.

Possibly related issues

  • y-scope/clp#667 Missing ingest jobs
    • The changes in this PR might help address the issue of job history tracking by introducing a more precise timestamp mechanism for job updates.
    • The new update_time column could potentially improve the reliability of job retrieval in the WebUI.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
components/webui/imports/api/ingestion/server/CompressionDbManager.js (2)

26-31: Update JSDoc to reflect parameter changes.

The JSDoc comment still references the removed limit parameter. Please update it to describe the lastUpdateDate parameter.

- * Retrieves the last `limit` number of jobs and the ones with the given
+ * Retrieves jobs updated since the given date and the ones with the given
 * @param {string} lastUpdateDate

62-64: Consider optimizing the SQL query structure.

The current implementation adds the UPDATE_TIME filter to each UNION query, which could impact performance. Consider moving the filter to a WHERE clause after the UNION to improve query efficiency.

- WHERE 
-     _id=${jobId} && 
-     ${COMPRESSION_JOBS_TABLE_COLUMN_NAMES.UPDATE_TIME} >= '${lastUpdateDate}'
+ WHERE _id=${jobId}

Then add after all UNION queries:

WHERE ${COMPRESSION_JOBS_TABLE_COLUMN_NAMES.UPDATE_TIME} >= '${lastUpdateDate}'
components/webui/imports/ui/IngestView/panels/IngestionJobs/IngestionJobRow.jsx (1)

109-115: Consider using dayjs for consistent date formatting.

The component already uses dayjs for duration calculations. For consistency, consider using it for formatting update_time as well.

- text={(null === job.update_time) ?
-     "null" :
-     new Date(job.update_time).toLocaleString()}/>
+ text={(null === job.update_time) ?
+     "null" :
+     dayjs(job.update_time).format('YYYY-MM-DD HH:mm:ss')}/>
components/webui/imports/api/ingestion/server/publications.js (2)

23-23: Add a comment explaining the magic number.

The constant CONST_FOR_DATE_FORMAT = 19 is used for date string manipulation but its purpose isn't clear. Add a comment explaining that it represents the length of the MySQL datetime format "YYYY-MM-DD HH:MM:SS".

+// Length of MySQL datetime format "YYYY-MM-DD HH:MM:SS"
 const CONST_FOR_DATE_FORMAT = 19;

48-50: Extract date formatting logic into a helper function.

The date string manipulation logic is duplicated. Extract it into a reusable helper function to improve maintainability.

+/**
+ * Formats a date object to MySQL datetime format
+ * @param {Date} date
+ * @return {string}
+ */
+const formatToMySQLDateTime = (date) => {
+    return date.toISOString()
+        .slice(0, CONST_FOR_DATE_FORMAT)
+        .replace("T", " ");
+};
+
-let lastUpdateDate = new Date().toISOString()
-    .slice(0, CONST_FOR_DATE_FORMAT)
-    .replace("T", " ");
+let lastUpdateDate = formatToMySQLDateTime(new Date());

 // In refreshCompressionJobs:
-    const newDate = new Date().toISOString()
-        .slice(0, CONST_FOR_DATE_FORMAT)
-        .replace("T", " ");
+    const newDate = formatToMySQLDateTime(new Date());

Also applies to: 107-109

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba63a76 and 0a3c885.

📒 Files selected for processing (7)
  • components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py (1 hunks)
  • components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py (5 hunks)
  • components/webui/imports/api/ingestion/constants.js (1 hunks)
  • components/webui/imports/api/ingestion/server/CompressionDbManager.js (3 hunks)
  • components/webui/imports/api/ingestion/server/publications.js (3 hunks)
  • components/webui/imports/ui/IngestView/panels/IngestionJobs/IngestionJobRow.jsx (1 hunks)
  • components/webui/imports/ui/IngestView/panels/IngestionJobs/index.jsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
components/webui/imports/ui/IngestView/panels/IngestionJobs/index.jsx (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/webui/imports/api/ingestion/constants.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/webui/imports/ui/IngestView/panels/IngestionJobs/IngestionJobRow.jsx (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/webui/imports/api/ingestion/server/CompressionDbManager.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/webui/imports/api/ingestion/server/publications.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (4)
components/webui/imports/api/ingestion/constants.js (1)

13-13: LGTM! The new UPDATE_TIME constant is well-placed.

The addition follows the existing naming convention and maintains logical grouping with other time-related columns.

components/webui/imports/ui/IngestView/panels/IngestionJobs/index.jsx (1)

50-50: LGTM! The new column header is well-integrated.

The "Last Updated" column follows the existing table design pattern with consistent right alignment.

components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py (1)

58-58: LGTM! The update_time column addition is well-structured.

The column definition aligns with other timestamp columns in the table and is appropriately positioned with other time-related fields.

components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py (1)

212-219: LGTM! Consistent timestamp updates across all job state changes.

The update_time is properly set at all critical points where job status changes:

  • When no tasks are created
  • When job starts
  • When job succeeds
  • When job fails

Also applies to: 233-235, 339-339, 350-350

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
components/webui/imports/api/ingestion/server/publications.js (1)

106-112: ⚠️ Potential issue

Prevent potential race condition in lastUpdateDate updates.

The current implementation has a potential race condition where jobs updated between saving newDate and updating lastUpdateDate could be missed. Consider using a transaction or updating lastUpdateDate before the query.

Additionally, consider adding error handling for date operations to prevent potential runtime errors.

#!/bin/bash
# Description: Check for potential race conditions by analyzing job update patterns

# Search for concurrent job updates in the codebase
rg -A 5 "UPDATE.*COMPRESSION_JOBS.*SET" 
🧹 Nitpick comments (2)
components/webui/imports/api/ingestion/server/publications.js (2)

23-24: Document the significance of the magic number.

The constant CONST_FOR_DATE_FORMAT = 19 appears to be the length of a MySQL datetime string (YYYY-MM-DD HH:mm:ss). Consider adding a comment explaining this or using a more descriptive constant name.

+// Length of MySQL datetime string format 'YYYY-MM-DD HH:mm:ss'
 const CONST_FOR_DATE_FORMAT = 19;

45-51: Extract date formatting logic into a reusable function.

The date formatting logic is duplicated between initialization and updates. Consider extracting it into a helper function to improve maintainability and reduce duplication.

+/**
+ * Formats a Date object to MySQL datetime string format
+ * @param {Date} date - The date to format
+ * @return {string} Formatted date string in 'YYYY-MM-DD HH:mm:ss' format
+ */
+const formatToMySQLDateTime = (date) => {
+    return date.toISOString()
+        .slice(0, CONST_FOR_DATE_FORMAT)
+        .replace("T", " ");
+};
+
-let lastUpdateDate = new Date().toISOString()
-    .slice(0, CONST_FOR_DATE_FORMAT)
-    .replace("T", " ");
+let lastUpdateDate = formatToMySQLDateTime(new Date());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a3c885 and 1fc3454.

📒 Files selected for processing (1)
  • components/webui/imports/api/ingestion/server/publications.js (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
components/webui/imports/api/ingestion/server/publications.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review

@junhaoliao junhaoliao requested a review from haiqi96 January 21, 2025 13:40
@junhaoliao
Copy link
Member

hey @haiqi96 , can you help review the package scripts?

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
components/webui/imports/api/ingestion/server/publications.js (1)

89-98: Consider using max retrieval_time for more accurate synchronization.

While using retrieval_time from the database is good, using the first job's timestamp might miss updates if multiple jobs have the same retrieval_time. Consider using the maximum retrieval_time from all jobs.

-        lastUpdateTimestampSeconds = jobs[0].retrieval_time;
+        lastUpdateTimestampSeconds = Math.max(...jobs.map(job => job.retrieval_time));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 433c66b and c0e830c.

📒 Files selected for processing (4)
  • components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py (1 hunks)
  • components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py (1 hunks)
  • components/webui/imports/api/ingestion/server/CompressionDbManager.js (1 hunks)
  • components/webui/imports/api/ingestion/server/publications.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py
  • components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py
🧰 Additional context used
📓 Path-based instructions (2)
components/webui/imports/api/ingestion/server/publications.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/webui/imports/api/ingestion/server/CompressionDbManager.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (3)
components/webui/imports/api/ingestion/server/CompressionDbManager.js (2)

23-28: LGTM! Clear and accurate docstring.

The docstring effectively communicates the function's purpose, parameter type, and return value structure.


29-47: LGTM! Well-implemented timestamp-based filtering.

The implementation effectively:

  • Uses FROM_UNIXTIME() for timestamp comparison
  • Includes retrieval_time for accurate synchronization
  • Maintains consistent ordering with ORDER BY
  • Properly parameterizes the query for security
components/webui/imports/api/ingestion/server/publications.js (1)

39-42: LGTM! Well-documented timestamp variable.

The variable declaration includes proper JSDoc typing and uses a clear, descriptive name that includes the unit.

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for making the adjustments. i believe the occasionally missing job is due to some rounding issue when we call the UNIX_TIME() function. With the proposed changes, I believe we can resolve the issue.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
components/webui/imports/api/ingestion/server/publications.js (1)

39-43: Global variable usage for timestamp is acceptable with single-threaded logic.

The definition of lastUpdateTimestampSeconds in the global scope works under the assumption that the refresh operation does not run concurrently. If concurrency is introduced in the future, consider adopting a more robust synchronization approach.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0e830c and 6603122.

📒 Files selected for processing (4)
  • components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py (2 hunks)
  • components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py (1 hunks)
  • components/webui/imports/api/ingestion/server/CompressionDbManager.js (1 hunks)
  • components/webui/imports/api/ingestion/server/publications.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py
  • components/clp-py-utils/clp_py_utils/initialize-orchestration-db.py
🧰 Additional context used
📓 Path-based instructions (2)
components/webui/imports/api/ingestion/server/publications.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

components/webui/imports/api/ingestion/server/CompressionDbManager.js (1)

Pattern **/*.{cpp,hpp,java,js,jsx,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (5)
components/webui/imports/api/ingestion/server/CompressionDbManager.js (3)

23-25: Clarify parameter usage in JSDoc.

The JSDoc now correctly indicates that the method retrieves all compression jobs updated on or after the given timestamp in seconds. Consider making it explicit that it uses UNIX time in seconds, if that is the underlying assumption.


29-29: Method signature update looks consistent.

Switching to a single parameter for timestamp-based filtering simplifies the query logic and aligns with the PR objective to retrieve all updated jobs.


31-44: ⚠️ Potential issue

Potentially incorrect subtraction of 1 using modulo arithmetic.

FROM_UNIXTIME(${lastUpdateTimestampSeconds}) - 1 could be interpreted in MySQL as subtracting one day or performing an unintentional numeric conversion, instead of subtracting one second. If your intention is to subtract one second from the resulting datetime, please consider using the DATE_SUB function:

-WHERE ${COMPRESSION_JOBS_TABLE_COLUMN_NAMES.UPDATE_TIME} >= 
-    FROM_UNIXTIME(${lastUpdateTimestampSeconds}) -1
+WHERE ${COMPRESSION_JOBS_TABLE_COLUMN_NAMES.UPDATE_TIME} >= 
+    DATE_SUB(FROM_UNIXTIME(${lastUpdateTimestampSeconds}), INTERVAL 1 SECOND)

Likely invalid or redundant comment.

components/webui/imports/api/ingestion/server/publications.js (2)

89-89: Good removal of limit-based argument.

Passing lastUpdateTimestampSeconds to getCompressionJobs better aligns with the new timestamp-based retrieval model.


92-98: Validate pecking order for retrieval_time.

When updating lastUpdateTimestampSeconds with jobs[0].retrieval_time, ensure the job at index 0 is guaranteed to have the maximum retrieval time. If another entry has a later retrieval_time but a smaller _id, it might be missed on subsequent calls. Consider computing the maximum retrieval_time across all returned jobs, if necessary.

@AVMatthews AVMatthews requested a review from junhaoliao January 23, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants